<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    /**
     * 双指针
     * @param {number[]} nums
     * @return {number}
     */
    var removeDuplicates = function (nums) {
        var len = 0
        for (let index = 0; index < nums.length; index++) {
            if (index === 0) {
                len++;
                continue
            }
            
            if (nums[index - 1] !== nums[index]) {
                nums[len] = nums[index]
                len++;
            }

        }
        return len
    };

    var nums = [1,1,2]
    var length = removeDuplicates(nums)
    console.log(nums);
    console.log(length);
</script>

</html>